
<template>
  <div class="home-page">
    <div class="head">
      <div class="logo"></div>
      <div class="user-btn">
        <img :src="userIcon" class="user-icon" />
        {{ user_name }}
      </div>
    </div>
    <div class="web-models-all">
      <div class="web-models-title">研发工作台</div>
      <ul class="web-models">
        <li @click="linkTo('powder')">
          <div class="web-model-icon">
            <div class="web-model-icon-img powder-icon-img"></div>
          </div>
          <div class="web-model-txt">
            <div class="web-model-txt-main">粉体复配应用</div>
            <div class="web-model-txt-sub">多元粉体复配计算</div>
          </div>
        </li>
        <li @click="linkTo('sem')">
          <div class="web-model-icon web-model-icon2">
            <div class="web-model-icon-img powder-icon-img"></div>
          </div>
          <div class="web-model-txt">
            <div class="web-model-txt-main">SEM图像识别</div>
            <div class="web-model-txt-sub">SEM图像识别</div>
          </div>
        </li>
        <li @click="linkTo('knowledgeGragh')">
          <div class="web-model-icon web-model-icon3">
            <div class="web-model-icon-img powder-icon-img"></div>
          </div>
          <div class="web-model-txt">
            <div class="web-model-txt-main">knowledge graph</div>
            <div class="web-model-txt-sub">知识图谱</div>
          </div>
        </li>
      </ul>
      <div class="web-models-title">综合行政</div>
      <ul class="web-models">
        <li>
          <div class="web-model-icon web-model-icon2">
            <div class="web-model-icon-img powder-icon-img"></div>
          </div>
          <div class="web-model-txt">
            <div class="web-model-txt-main">综合行政</div>
            <div class="web-model-txt-sub">综合行政</div>
          </div>
        </li>
      </ul>

      <div class="web-models-title">其他</div>
      <ul class="web-models">
        <li>
          <div class="web-model-icon web-model-icon3">
            <div class="web-model-icon-img powder-icon-img"></div>
          </div>
          <div class="web-model-txt">
            <div class="web-model-txt-main">其他</div>
            <div class="web-model-txt-sub">其他</div>
          </div>
        </li>
      </ul>
    </div>
    <div class="copyright">copyright@EpiScience 沪ICP备2025111528号</div>
  </div>
</template>
 
<script>
import {
  app_access_token,
  access_token,
  getcode,
  feishuUserAdd,
  feishuUserQuery,
} from "@/api/index";

import { deepClone } from "@/utils";
import ResizeMixin from "@/utils/ResizeHandler";
import Cookies from "js-cookie";
export default {
  name: "index",
  data() {
    return {
      user_name: "",
      mobile: "",
      userIcon: require("@/assets/images/userIcon.png"),
    };
  },
  mixins: [ResizeMixin],
  components: {},
  watch: {},
  computed: {},
  async created() {
    let mobile = localStorage.getItem("feishu_mobile");

    if (mobile) {
      Cookies.set("feishu_mobile", mobile);
      let res = await feishuUserQuery({ mobile });
      if (res.data) {
        this.user_name = res.data["name"];
        this.mobile = mobile;
      }
    } else {
      if (process.env.NODE_ENV === "production") {
        let url = this.getLocalhost();
 
        let code = this.GetQueryString("code");
        if (code) {
          let app_access_token = await this.app_access_token();
          if (app_access_token) {
            this.access_token({ code, app_access_token });
          }
        } else {
          this.getcode(url);
        }
      }
    }
  },

  beforeDestroy() {},
  methods: {
    async linkTo(url) {
      // 172.168.110.131
      // this.feishuUserAdd({email:"",mobile:"+8615316201143",name:"仇晓怡",open_id:"ou_437f69cc96f2e93841217d6239de634c",union_id:"1212",user_id:"dada",avatar_url:"https://s3-imfile.feishucdn.com/static-resource/v1/v3_00bu_ed224159-84a7-4234-96d7-bca60d9059bg~?image_size=72x72&cut_type=&quality=&format=image&sticker_format=.webp"})
      if (url === "powder") {
 
        this.$router.push({ path: "/powder" });
      } else if(url === "sem") {
        let _url = process.env.NODE_ENV === "production" ?"http://172.168.110.131:8084":"http://172.168.110.87:8084"
        let mobile = this.mobile.replace(/\+86/, "");
        window.open(
          _url+"?feishu_mobile="+mobile,
          "_blank"
        );
      } else if (url === "knowledgeGragh") {
        let openUrl =
          process.env.NODE_ENV === "production"
            ? "http://1.13.176.116:8083"
            : "http://localhost:8013";
        window.open(
          openUrl + "?mobile=" + encodeURIComponent(this.mobile),
          "_blank"
        );
      }
    },
    async getcode(url) {
      await getcode(url);
    },
    async access_token(data) {
      let res = await access_token(data);
      if (res["resp"].code === 0) {
        let data = res["resp"]["data"];
        console.log(data, "##########access_token");
        this.user_name = data["name"];
        let feishu_res = await feishuUserQuery({ mobile: data["mobile"] });
        if (!feishu_res.data) {
          await this.feishuUserAdd(data);
        }
        localStorage.setItem("feishu_mobile", data["mobile"]);
        Cookies.set("feishu_mobile", data["mobile"]);
      }
      console.log(res, "####res");
    },
    async feishuUserAdd(data) {
      await feishuUserAdd(data);
    },

    async app_access_token() {
      let res = await app_access_token();
      console.log(res, "::::app_access_token");
      return res["resp"];
    },
    getLocalhost() {
      var protocol = window.location.protocol;
      var hostname = window.location.hostname;
      var port = window.location.port ? ":" + window.location.port : ""; // 如果端口号不是默认，则添加':'和端口号
      var baseUrl = protocol + "//" + hostname + port;
      return baseUrl;
    },
    GetQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return unescape(r[2]);
      return null;
    },
  },
};
</script>
 <style src="@/assets/index.scss" scoped lang="scss"></style>